from alg import Solution
from gen import generate_random_sudoku


def print_board(board):
    """美观打印数独棋盘"""
    for i in range(9):
        if i % 3 == 0 and i != 0:
            print("- - - - - - - - - - -")
        for j in range(9):
            if j % 3 == 0 and j != 0:
                print("|", end=" ")
            print(board[i][j], end=" ")
        print()


def main():
    # 生成随机数独谜题
    difficulty = 'medium'  # 可选: 'easy', 'medium', 'hard'
    puzzle = generate_random_sudoku(difficulty)

    print(f"随机生成的数独谜题 (难度: {difficulty}):")
    print_board(puzzle)

    # 复制谜题用于求解
    board_to_solve = [row.copy() for row in puzzle]

    # 使用求解器解决数独
    solver = Solution()
    solver.solveSudoku(board_to_solve)

    print("\n求解后的数独:")
    print_board(board_to_solve)


if __name__ == "__main__":
    main()